var http = require("http"),
	url = require('url');

function startServer(route, handle) {

	function onRequest(request, response) {
		var name = getPathName(request.url),
			postData = '';

		if(name !== '/favicon.ico') {

			// request.setEncoding('utf-8');
			// request.addListener('data', function(block) {

			// 	postData += block;
			// 	console.log("Received POST data chunk '"+ block + "'.");
			// });
			// request.addListener('end',function() {

			// 	route(handle, name, request, response); // 处理的函数、请求的地址、回应、数据
			// });
			route(handle, name, request, response); // 处理的函数、请求的地址、回应、数据
		}
	}

	function getPathName(urlPath) {
		return url.parse(urlPath).pathname;
	}

	http.createServer(onRequest).listen(8888);
	console.log('Server has started!');
}

exports.startServer = startServer; // 给外面的文件暴露出接口